﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_TraCheckIsbidcompany_PSFinfo : System.Web.UI.Page
{ 
  static string _stHspid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
       
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupplyCompanyCheck);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                string _SupplyGoodsId = "", _areaid = "",_area="", _Accountid_ps_B1 = "";
                System.Data.IDataReader drn;
                Db dbn = new Db();
                string strNp = "select SupplyGoodsId,areaid,areaname,Accountid_ps_B1,NopssReason from SupplyPlan_GoodsNext where id=" + SysFun.ToTrim(Request.QueryString["id"]);
                drn = dbn.DataReader(strNp);
                if (drn.Read())
                {
                    _SupplyGoodsId = SysFun.ToTrim(drn["SupplyGoodsId"].ToString());
                    _areaid = SysFun.ToTrim(drn["areaid"].ToString());
                    _area = SysFun.ToTrim(drn["areaname"].ToString());
                    _Accountid_ps_B1 = SysFun.ToTrim(drn["Accountid_ps_B1"].ToString());
                    TextBox1.Text = SysFun.ToTrim(drn["NopssReason"].ToString());
                }
                drn.Dispose();
                drn.Close();
                dbn.Close();
                strNp = "select hospitalname,hspid from PurchaseTable where SupplyGoodsId=" + _SupplyGoodsId + " and areaid=" + _areaid + " and accountid_ps=" + _Accountid_ps_B1;
                dbn = new Db();
                drn = dbn.DataReader(strNp);
 
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                int k = 1, j = 0;
                string AreaName = "";
                sb.Append("<table width='98%' cellspacing='0' border='1' cellpadding='3'>");
                while (drn.Read())
                {
                    if (AreaName != _area)
                    {
                        AreaName = _area;
                        if (j != 0)
                        {

                            switch (k % 4)
                            {
                                case 0:
                                    sb.Append("</tr>");
                                    break;
                                case 3:
                                    sb.Append("<td>&nbsp;</td></tr>");
                                    break;
                                case 2:
                                    sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                                    break;
                                case 1:
                                    sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                                    break;

                            }
                        }
                        j = 1;
                        k = 1;
                        sb.Append("<tr>");
                        sb.Append("<td colspan=3 style='color: #ff0033'>" + _area + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                    }
                    else
                    {
                        if (k % 4 == 0)
                        {
                            j = 1;
                            k = 1;

                            sb.Append("</tr><tr>");
                        }
                    }
                    sb.Append("<td>" + drn["hospitalname"].ToString() + "</td>");
                    _stHspid += ',' + drn["hspid"].ToString();
                    k++;

                }
                switch (k % 4)
                {
                    case 0:
                        sb.Append("</tr>");
                        break;
                    case 3:
                        sb.Append("<td>&nbsp;</td></tr>");
                        break;
                    case 2:
                        sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                        break;
                    case 1:
                        sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                        break;

                }

                sb.Append("<table>");
                Label4.Text = sb.ToString();
                drn.Close();
                drn.Dispose();
                dbn.Close();
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)  //审核通过
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            Db db = new Db();
            string strSql = "update SupplyPlan_GoodsNext set NopssReason='" + SysFun.ToTrim(TextBox1.Text) + "', PS_ChangeStatus=1,Accountid_sh='" + SysFun.ToLong(_Account.AccountId) + "',Accountname_shr='" + _Account.AccountName + "' ,CheckStatusDatetime=getdate() where id=" + SysFun.ToTrim(Request.QueryString["id"]);
            db.Command(strSql);
            db.Close();
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_GoodsNext", strSql, "../Agency/TraCheckIsbidcompany_PSFinfo.aspx");
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您无权审核商品信息！！！');</script>");
        }

    }
    protected void Button3_Click(object sender, EventArgs e)  //审核不通过
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            Db db = new Db();
            string strSql = "update SupplyPlan_GoodsNext set NopssReason='" + SysFun.ToTrim(TextBox1.Text) + "', PS_ChangeStatus=2,Accountid_sh='" + SysFun.ToLong(_Account.AccountId) + "',Accountname_shr='" + _Account.AccountName + "' ,CheckStatusDatetime=getdate() where id=" + SysFun.ToTrim(Request.QueryString["id"]);
            db.Command(strSql);
            db.Close();
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_GoodsNext", strSql, "../Agency/TraCheckIsbidcompany_PSFinfo.aspx");
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您无权审核商品信息！！！');</script>");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)//未审核
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            if (_stHspid != "")
            {
                updateHospitalPurchase();//删除医院的采购目录的该品种的配送企业 
            }
            Db db = new Db();
            string strSql = "update SupplyPlan_GoodsNext set NopssReason='" + SysFun.ToTrim(TextBox1.Text) + "', PS_ChangeStatus=0,Accountid_sh='" + SysFun.ToLong(_Account.AccountId) + "',Accountname_shr='" + _Account.AccountName + "' ,CheckStatusDatetime=getdate() where id=" + SysFun.ToTrim(Request.QueryString["id"]);
            db.Command(strSql);
            db.Close();
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_GoodsNext", strSql, "../Agency/TraCheckIsbidcompany_PSFinfo.aspx");
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您无权审核商品信息！！！');</script>");
        }
    }

    private void updateHospitalPurchase()
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_stHspid != "")
        {
            Db db = new Db();
            string strSql = "update HospitalPurchase set accountid_ps=null,planpurnum=null where hspid in(" + _stHspid.Remove(0, 1) + ")";
            db.Command(strSql);
            db.Close();
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "HospitalPurchase", strSql, "../Agency/TraCheckIsbidcompany_PSFinfo.aspx"); 
        }
    }
}
